{% set no_path_section = true %}
{% extends "layout/basic.html" %}
{% import "components/contest.html" as contest with context %}
{% block content %}
{% if handler.domain['bulletin'] %}
<div class="row">
  <div class="large-12 columns">
    <div class="section">
      <div class="section__body typo">
        {{ handler.domain['bulletin']|markdown }}
      </div>
    </div>
  </div>
</div>
{% endif %}
<div class="row">
  <div class="large-9 columns">
  {% if not tdocs %}
    <!-- no contest -->
  {% else %}
    <div class="section page--contest_main">
      <div class="section__header">
        <h1 class="section__title">{{ _('Contest') }}</h1>
      </div>
      <ol class="section__list contest__list">
      {% for tdoc in tdocs %}
        <li class="section__list__item contest__item contest-type--{{ vj4.constant.contest.RULE_ID[tdoc['rule']] }}">
          <div class="media">
            <div class="media__left medium">
              <div class="contest__date numbox">
                <div class="numbox__num large">{{ datetime_span(tdoc['begin_at'], false, '%d') }}</div>
                <div class="numbox__text">{{ datetime_span(tdoc['begin_at'], false, '%Y-%m') }}</div>
              </div>
            </div>
            <div class="media__body medium">
              <h1 class="contest__title"><a href="{{ reverse_url('contest_detail', tid=tdoc['doc_id']) }}" data-emoji-enabled>{{ tdoc['title'] }}</a></h1>
              <ul class="supplementary list">
                <li>
                  <a href="{{ reverse_url('contest_main') }}?rule={{ tdoc['rule'] }}" class="contest-type-tag"><span class="icon icon-award"></span>{{ vj4.constant.contest.RULE_TEXTS[tdoc['rule']] }}</a>
                </li>
                <li>
                  <span class="icon icon-schedule--fill text-blue"></span> {{ contest.render_duration(tdoc) }} {{ _('hour(s)') }}
                </li>
                <li>
                  <span class="icon icon-user--multiple"></span> {{ tdoc['attend']|default(0) }}
                </li>
              {% if tsdict[tdoc['doc_id']]['attend'] == 1 %}
                <li class="contest__info-attended">
                  <span class="icon icon-check"></span> {{ _('Attended') }}
                </li>
              {% endif %}
              </ul>
            </div>
          </div>
        </li>
      {% endfor %}
      </ol>
    </div>
  {% endif %}
  {% if not trdocs %}
    <!-- no training -->
  {% else %}
    <div class="section page--training_main">
      <div class="section__header">
        <h1 class="section__title">{{ _('Training') }}</h1>
      </div>
      {% with tdocs=trdocs, tsdict=trsdict %}
      <ol class="section__list all primary training__list">
        {% for tdoc in tdocs %}
        <li class="section__list__item training__item">
          <div class="media">
            <div class="media__left middle">
              <div class="training__participants numbox">
                <div class="numbox__num large">{{ tdoc['enroll']|default(0) }}</div>
                <div class="numbox__text">{{ _('Enrolled') }}</div>
              </div>
            </div>
            <div class="media__body middle">
              <h1 class="training__title"><a href="{{ reverse_url('training_detail', tid=tdoc['doc_id']) }}" data-emoji-enabled>{{ tdoc['title'] }}</a></h1>
              <div class="training__intro typo">
                <p>{{ tdoc['content'] }}</p>
              </div>
              <ul class="supplementary list training__progress">
                <li>
                  <span class="icon icon-flag text-blue"></span> {{ _('{0} sections').format(tdoc['dag']|length) }}, {{ _('{0} problems').format(handler.get_pids(tdoc)|length) }}
                </li>
                <li>
                {% if tsdict[tdoc['doc_id']]['enroll'] %}
                  {% if not tsdict[tdoc['doc_id']]['done'] %}
                  <span class="icon training-status--icon progress"></span>
                  <span class="training-status--text progress">{{ _('Completed') }} {{ (100 * tsdict[tdoc['doc_id']]['done_pids']|length / handler.get_pids(tdoc)|length)|round|int }}%</span>
                  {% else %}
                  <span class="icon training-status--icon done"></span>
                  <span class="training-status--text done">{{ _('Completed') }} 100%</span>
                  {% endif %}
                {% elif handler.has_priv(vj4.model.builtin.PRIV_USER_PROFILE) %}
                  <span class="icon training-status--icon outside"></span> <span class="training-status--text outside">{{ _('Not Enrolled') }}</span>
                {% endif %}
                </li>
              </ul>
            </div>
          </div>
        </li>
        {% endfor %}
      </ol>
      {% endwith %}
    </div>
  {% endif %}
  {% if not ddocs %}
    <!-- no discussion -->
  {% else %}
    <div class="section page--discussion_main">
      <div class="section__header">
        <h1 class="section__title">{{ _('Discussion') }}</h1>
      </div>
      {% include "partials/discussion_list.html" %}
    </div>
  {% endif %}
  </div>
  <div class="large-3 columns">
    {% include 'discussion_nodes_widget.html' %}
  {% if domain_id == vj4.model.builtin.DOMAIN_ID_SYSTEM %}
    <div class="section side">
      <div class="section__header">
        <h1 class="section__title">{{ _('Recommended') }}</h1>
      </div>
      <div class="section__body"><ul class="group-list">
        <li class="group-list__item">
          <h2 class="section__title">{{ _('Chinese') }}</h2>
          <ol class="chip-list">
            <li class="chip-list__item"><a class="typo-a" href="https://www.xuetangx.com/courses/course-v1:TsinghuaX+30240184+sp/about" target="_blank">清华数据结构 MOOC 上</a><a class="typo-a" href="https://www.xuetangx.com/courses/course-v1:TsinghuaX+30240184_2X+sp/about" target="_blank">/下</a></li>
            <li class="chip-list__item"><a class="typo-a" href="https://www.51nod.com/" target="_blank">51Nod</a></li>
            <li class="chip-list__item"><a class="typo-a" href="https://www.luogu.org/" target="_blank">洛谷</a></li>
            <li class="chip-list__item"><a class="typo-a" href="https://www.rqnoj.cn/" target="_blank">RQNOJ</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://www.lydsy.com/JudgeOnline/" target="_blank">BZOJ</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://acm.zju.edu.cn/onlinejudge/" target="_blank">ZOJ</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://uoj.ac/" target="_blank">UOJ</li>
          </ol>
        </li>
        <li class="group-list__item">
          <h2 class="section__title">{{ _('English') }}</h2>
          <ol class="chip-list">
            <li class="chip-list__item"><a class="typo-a" href="https://www.topcoder.com/" target="_blank">TopCoder</a></li>
            <li class="chip-list__item"><a class="typo-a" href="https://uva.onlinejudge.org/" target="_blank">UVa</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://codeforces.com/" target="_blank">Codeforces</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://www.usaco.org/" target="_blank">USACO</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://spoj.pl/" target="_blank">SPOJ</a></li>
            <li class="chip-list__item"><a class="typo-a" href="http://poj.org/" target="_blank">POJ</a></li>
          </ol>
        </li>
      </ul></div>
    </div>
  {% endif %}
  </div>
</div>
{% endblock %}
